﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Threading.Tasks;
using System.Transactions;

namespace Moon.Sql
{
    public interface IDatabase : ITransaction, IDisposable
    {
        string DbId { get; }
        /// <summary>
        /// 当前连接
        /// </summary>
        IDbConnection Connection { get; }
        IDbTransaction Transaction { get; }
        string ConnectionString { get; }
        /// <summary>
        /// 数据库超时时间 默认30秒
        /// </summary>
        int CommandTimeout { get; set; }
        IDbConnection OpenConnection();
        void CloseConnection();
        /// <summary>
        /// 数据库方言
        /// </summary>
        ISqlDialect SqlDialect { get; }
        GridReader QueryMultiple(string sql, object param = null, CommandType? commandType = null);
        Task<GridReader> QueryMultipleAsync(string sql, object param = null, CommandType? commandType = null);
        List<T> Query<T>(string sql, object param = null, CommandType? commandType = null);
        Task<List<T>> QueryAsync<T>(string sql, object param = null, CommandType? commandType = null);
        T QueryFirst<T>(string sql, object param = null, CommandType? commandType = null);
        Task<T> QueryFirstAsync<T>(string sql, object param = null, CommandType? commandType = null);
        T ExecuteScalar<T>(string sql, object param = null, CommandType? commandType = null);
        Task<T> ExecuteScalarAsync<T>(string sql, object param = null, CommandType? commandType = null);
        int Execute(string sql, object param = null, CommandType? commandType = null);
        Task<int> ExecuteAsync(string sql, object param = null, CommandType? commandType = null);
        QueryPageResult<T> QueryPage<T>(string sql, object param = null);
        Task<QueryPageResult<T>> QueryPageAsync<T>(string sql, object param = null);
        DataTable Query(string sql, object param = null, CommandType? commandType = null);
        Task<DataTable> QueryAsync(string sql, object param = null, CommandType? commandType = null);
        int BulkInsert(DataTable table, string tableName);
        Task<int> BulkInsertAsync(DataTable table, string tableName);
        DataSet ExecuteDataSet(string sql, object param = null, CommandType? commandType = null);
        IDataReader ExecuteReader(string sql, object param = null, CommandType? commandType = null);
        Task<IDataReader> ExecuteReaderAsync(string sql, object param = null, CommandType? commandType = null);
        IAop Aop { get; set; }
    }
}